<?php
	require_once("includes/connect.php");
	require_once("includes/function.php");

	$cheque_no = $_REQUEST["cheque_no"];
	//$val = $_REQUEST["val"];
	//echo $petition_id;

	$db = new myDBS;


	$sql ="SELECT cheque_no, branch_name, bank_name, SUM( welfare ) AS welfare FROM tbl_welfare WHERE  cheque_no ='$cheque_no' GROUP BY cheque_no, branch_name, bank_name";
	
	$result = $db->runSQL($sql);
	$rows = $db->fetch_object ( $result );

	$C = new Currency;
	

// just require TCPDF instead of FPDF

	//define('FPDF_FONTPATH','fpdf/font/');
	require_once('fpdf/TCPDF/tcpdf.php');
	require_once('fpdf/FPDI/fpdi.php');

	class PDF extends FPDI {
		/**
		 * "Remembers" the template id of the imported page
		 */
		var $_tplIdx;
		
		/**
		 * include a background template for every page
		 */
		function Header() {
			if (is_null($this->_tplIdx)) {
				$this->setSourceFile('pdf_form/cash.pdf');
				$this->_tplIdx = $this->importPage(1);
			}
			$this->useTemplate($this->_tplIdx);
			
			/*
			//$this->AddFont('THSarabunNew','','THSarabunNew.php');
			//$this->SetFont('THSarabunNew', '', 9);
			$this->SetTextColor(255);
			$this->SetXY(60.5, 24.8);
			$this->Cell(0, 8.6, "TCPDF and FPDI");
			*/
		}
		
		function Footer() {}
	}

	// initiate PDF

//Add a custom size  

	$pagelayout = array(100,160);
	$pdf = new PDF($orientation='L', $unit='mm', $pagelayout, $unicode=true, $encoding='UTF-8', $diskcache=false, $pdfa=false);
	$pdf->SetMargins(PDF_MARGIN_LEFT, 40, PDF_MARGIN_RIGHT);
	$pdf->SetAutoPageBreak(true, 40);
	$pdf->setFontSubsetting(false);


	// add a page
	$pdf->AddPage();

	//$pdf->AddFont('THSarabunNew','','THSarabunNew.php');
	//$pdf->SetFont("freeserif", "", 12);
	$pdf->SetFont('thsarabunb','B',15);
	// now write some text above the imported page


	$pdf->SetXY(22, 8);
	$pdf->Write(0, $rows->bank_name);

	$pdf->SetXY(75, 8);
	$pdf->Write(0, $rows->branch_name);

	$pdf->SetXY(125, 8);
	$pdf->Write(0, $rows->cheque_no);

	$pdf->SetXY(110, 18);
	$date = date_create($rows->cheque_date);
	$pdf->Write(0, date_format($date, "d/m/Y"));

	$pdf->SetXY(20, 30.5);
	//$pdf->Write(0, $rows->company_name);

	$pdf->SetXY(87, 30.5);
	//$pdf->Write(0, "ทวีศักดิ์");
	$html="<del>XX</del>";
	$pdf->writeHTML($html, true, false, true, false, '');

	$style2 = array('width' => 0.5, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(255, 0, 0));
	$pdf->Line(87.5, 37, 92.5, 37, $style2);

	$pdf->SetXY(85.5, 37);
	$pdf->Write(0, "100");

	$pdf->SetXY(25, 41.5);
	$pdf->Write(0, number_format($rows->welfare,2));


	$pdf->SetXY(8, 52);
	$pdf->Write(0, $C->bahtThai($rows->welfare));

	
	//$pdf->Write(0, "asdfasdf");

	/*
	$pdf->SetXY(73, 69);
	$pdf->Cell(41,0,number_format($rows->inpValues, 2),0,0,'R');
	*/

	$pdf->Output('output_cash.pdf', 'I');
?>